<template>
  <el-dialog
    title="添加用户"
    @close="aditClosed"
    :visible.sync="dialogVisible"
    width="750px"
  >
    <el-form
      :model="addUsrInfo"
      :rules="rules"
      ref="addRuleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="addUsrInfo.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" type="password" prop="password">
        <el-input v-model="addUsrInfo.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="addUsrInfo.email"></el-input>
      </el-form-item>
      <el-form-item label="手机" prop="mobile">
        <el-input v-model.number="addUsrInfo.mobile"></el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="postUserList">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { UserInfoRules } from '@/common/mixin'
import { postUserListApi } from '@/Utils/Api/getUserInfoApi'
export default {
  name: 'addUserBox',
  mixins: [UserInfoRules],
  data () {
    return {
      dialogVisible: false,
      addUsrInfo: {
        username: '',
        password: '',
        email: '',
        mobile: '17382930920'
      }
    }
  },
  components: {},
  created () {},
  mounted () {},
  methods: {
    // 添加
    postUserList () {
      this.$refs.addRuleForm.validate(async vail => {
        if (!vail) return
        try {
          const { data } = await postUserListApi(this.addUsrInfo)
          if (data.meta.status === 200) {
          // 重新获取列表,刷新视图
            this.$emit('getRoleInfoDrive')
            this.dialogVisible = false
            return this.$message({
              type: 'success',
              message: data.meta.msg
            })
          } else {
            this.$message({
              type: 'error',
              message: data.meta.msg
            })
          }
        } catch (error) {
          console.log(error)
        }
      })
    },
    // 关闭窗口后清空表单
    aditClosed () {
      this.$refs.addRuleForm.resetFields()
    }
  },
  computed: {},
  watch: {}
}
</script>

<style scoped>
</style>
